package gd.qaq.blue.bluespick.util.area;

import org.bukkit.Location;
import org.bukkit.World;

public final class Chunk
{
    private final World world;
    private final int chunkX;
    private final int chunkZ;
    
    public Chunk(final Location location) {
        this.world = location.getWorld();
        this.chunkX = location.getBlockX() >> 4;
        this.chunkZ = location.getBlockZ() >> 4;
    }
    
    public Chunk(final World world, final int chunkX, final int chunkZ) {
        this.world = world;
        this.chunkX = chunkX;
        this.chunkZ = chunkZ;
    }
    
    public World getWorld() {
        return this.world;
    }
    
    public int getChunkX() {
        return this.chunkX;
    }
    
    public int getChunkZ() {
        return this.chunkZ;
    }
    
    @Override
    public boolean equals(final Object obj) {
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof Chunk)) {
            return false;
        }
        final Chunk other = (Chunk)obj;
        return this.world.equals(other.world) && this.chunkX == other.chunkX && this.chunkZ == other.chunkZ;
    }
    
    @Override
    public int hashCode() {
        return this.world.hashCode() * 37 * 37 + this.chunkX * 37 + this.chunkZ;
    }
    
    @Override
    public String toString() {
        return String.format("{world:%s,chunkx:%s,chunkz:%s}", this.getWorld().getName(), this.getChunkX(), this.getChunkZ());
    }
}
